library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(dplyr)
library(tidyr)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggridges)
library(httr)
##
## Attaching package: 'httr'
## The following object is masked from 'package:plotly':
##
## config
library(jsonlite)
##
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
##
## flatten
library(flexdashboard)
Column
Chart A
data("instacart")
instacart_1 =
count(instacart, department) %>%
arrange(n) %>%
mutate(
department = factor(department, levels = department)
)
instacart_1 %>%
plot_ly(x = ~n, y = ~department, color = ~department, type = "bar", colors = "viridis")
Column
Chart B
instacart_2 = instacart %>%
filter( department == "dairy eggs") %>%
mutate(department = str_to_title(department)) %>%
mutate(
department = fct_infreq(department),
department = fct_recode(department))
# group_by(aisle, days_since_prior_orde) %>%
# summarize(n_obs = n())
# select(department, order_number, days_since_prior_order)
instacart_2 %>%
plot_ly(x = ~aisle, y = ~days_since_prior_order, color = ~department, alpha = .5,
type = "scatter", mode = "markers"
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
Chart C
data("instacart")
instacart_3 = instacart %>%
mutate(department = str_to_title(department)) %>%
mutate(
department = fct_infreq(department),
department = fct_recode(department))
instacart_3 %>%
plot_ly(
x = ~department, y = ~days_since_prior_order, color = ~department,
type = "box", colors = "viridis"
)